package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-04
 * Time: 20:49
 */

/**
 * 创建一个类,实现饿汉模式
 * 所谓饿汉,就是类被加载的时候就会创建这个单例的实例
 */
class Singleton {
    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    //构造方法设为私有,防止其他的类创建实例
    private Singleton() {

    }
}

public class demo22 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
    }
}
